package cn.kgc.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class jsq1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html");
        String num1 = req.getParameter("name");
        Integer n1 = Integer.parseInt(num1);
        String num2 = req.getParameter("name1");
        Integer n2 = Integer.parseInt(num2);
        double jieguo = 0;
        String fuhao = req.getParameter("fuhao");
        switch (fuhao) {
            case "1":
                fuhao = "+";
                jieguo = n1 + n2;
                break;
            case "2":
                fuhao = "-";
                jieguo = n1 - n2;
                break;
            case "3":
                fuhao = "*";
                jieguo = n1 * n2;
                break;
            case "4":
                fuhao = "/";
                jieguo = n1 / n2;
                break;
        }
        req.setAttribute("n1", n1);
        req.setAttribute("n2", n2);
        req.setAttribute("fuhao", fuhao);
        req.setAttribute("jieguo", jieguo);
        req.getRequestDispatcher("jsp1.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
